using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using HappySprite;
using HappySprite.Graphics;

namespace HappyInvaders
{
    class InvaderAlphaVisual : InvaderVisual
    {
        public InvaderAlphaVisual()
        {
            Images[0] = new ImageMap(Constants.InvaderAlphaTexture1);
            Images[1] = new ImageMap(Constants.InvaderAlphaTexture2);
            Item.RenderItem.Width = Constants.InvaderWidth - 4;
            Item.RenderItem.ImageMap = Images[0];
            Item.RenderItem.Tint = Color.DarkCyan;
        }
    }

    class InvaderBetaVisual : InvaderVisual
    {
        public InvaderBetaVisual()
        {
            Images[0] = new ImageMap(Constants.InvaderBetaTexture1);
            Images[1] = new ImageMap(Constants.InvaderBetaTexture2);
            Item.RenderItem.Width = Constants.InvaderWidth - 2;
            Item.RenderItem.ImageMap = Images[0];
            Item.RenderItem.Tint = Color.DarkGoldenrod;
        }
    }

    class InvaderGammaVisual : InvaderVisual
    {
        public InvaderGammaVisual()
        {
            Images[0] = new ImageMap(Constants.InvaderGammaTexture1);
            Images[1] = new ImageMap(Constants.InvaderGammaTexture2);
            Item.RenderItem.Width = Constants.InvaderWidth;
            Item.RenderItem.ImageMap = Images[0];
            Item.RenderItem.Tint = Color.DarkGreen;
        }
    }

    abstract class InvaderVisual : Visual
    {
        View owner;
        int flip;

        protected ImageMap[] Images = new ImageMap[2];

        public InvaderVisual()
        {
            Item.RenderItem.Height = Constants.InvaderHeight;
        }

        internal override void OnAdd(View view)
        {
            owner = view;
            owner.InvadersLeft++;
            flip = 0;

            Item.RenderItem.ImageMap = Images[0];
        }   

        internal override void OnRemove()
        {
            owner.InvadersLeft--;
        }

        public override void SetPosition(Vector2 position)
        {
            FlipAnimation();
            base.SetPosition(position);
        }

        void FlipAnimation()
        {
            flip ^= 1;
            Item.RenderItem.ImageMap = Images[flip];
        }
    }
}
